<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>用户修改</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" >
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
</head>
<body>
<form class="layui-form" action="" lay-filter="example">
<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="tel" name="phone" lay-verify="required|phone" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">学历</label>
        <div class="layui-input-inline">
            <select name="education">
                <option value="无" selected="">无</option>
                <option value="小学" >小学</option>
                <option value="高中">高中</option>
                <option value="大专">大专</option>
                <option value="本科">本科</option>
                <option value="硕士">硕士</option>
                <option value="博士及以上">博士及以上</option>

            </select>
        </div>
    </div>
</div>

<div class="layui-form-item">
    <div class="layui-inline">
        <label class="layui-form-label">生日</label>
        <div class="layui-input-block">
            <input type="text" name="birthday" id="date1" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">姓名</label>
        <div class="layui-input-inline">
            <input type="text" name="passengerName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
</div>

<div class="layui-form-item">
    <input name="id" type="hidden" />
    <div class="layui-form-item">
        <label class="layui-form-label">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="gender" value="1" title="男" checked="">
            <input type="radio" name="gender" value="0" title="女">
        </div>
    </div>
<!--    <div class="layui-upload layui-form-item">-->
<!--        <button type="button" class="layui-btn" id="test1">上传头像</button>-->
<!--        <div class="layui-upload-list" style="width: 200px ; height: 200px ">-->
<!--            <img class="layui-upload-img" id="demo1">-->
<!--            <p id="demoText"></p>-->
<!--        </div>-->
<!--        <div style="width: 95px;">-->
<!--            <div class="layui-progress layui-progress-big" lay-showpercent="yes" lay-filter="demo">-->
<!--                <div class="layui-progress-bar" lay-percent=""></div>-->
<!--            </div>-->
<!--        </div>-->
<!--    </div>-->
</div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
</body>

<script src="/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
<script>
    layui.use(['form', 'layedit', 'laydate','upload','element'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,upload = layui.upload
            ,laydate = layui.laydate
            ,element = layui.element
            , $ = layui.jquery

        // 对页面中的表单进行默认渲染
        form.render();
        laydate.render({
            elem: '#date1'
        });
        // 通过ajax 对表单中内容进行赋值
        $.ajax({
            url:"/customerAdmin/updateShow"
            ,dataType: "json"
            // 使用js的全局变量 parent.变量名
            ,data:{ id: parent.customerId}
            ,success:function (data) {
                // 请求后端成功后，将查询的数据设置道页面中
                if (data.code == 200 ){
                    // responseData { code:"" ; msg:"" ; data:"" }
                    form.val('example', {
                        "phone": data.data.phone
                        ,"passengerName":data.data.passengerName
                        ,"education":data.data.education
                        ,"birthday":data.data.birthday
                        ,"gender":data.data.gender
                        ,"id":parent.customerId
                    });
                }
            }
        })

        //监听提交
        form.on('submit(demo1)', function(data){
            // 监听到点击事件发生时,进行修改操作
            console.log(data.field)
            $.ajax({
                url:"/customerAdmin/update"
                ,data:data.field
                ,dataType: "json"
                ,success:function (data) {
                    if (data.code ==200){
                        //关闭父级窗口
                        parent.location.reload();
                    }
                }
            })
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // })
            // 阻止提交事件的发生
            return false;
        });

        //常规使用 - 普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'https://httpbin.org/post' //此处用的是第三方的 http 请求演示，实际使用时改成您自己的上传接口即可。
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });

                element.progress('demo', '0%'); //进度条复位
                layer.msg('上传中', {icon: 16, time: 0});
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }
                //上传成功的一些操作
                //……
                $('#demoText').html(''); //置空上传失败的状态
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
            //进度条
            ,progress: function(n, elem, e){
                element.progress('demo', n + '%'); //可配合 layui 进度条元素使用
                if(n == 100){
                    layer.msg('上传完毕', {icon: 1});
                }
            }
        });




    });
</script>
</html>